2.3.1 Variables

Variables in mathematics are often single letters. Myron, like other computer languages, allows multi-letter variables with numbers mixed in, as shown in the first part of Figure 2.6. Myron even allows variables composed of characters from the Greek alphabet. So variable names like x1, Moon42 and Πιε are allowed.


(a) Variable

(b) Identifier

(c) Variable decorations
Figure 2.6 Variable and decoration

Variables can be decorated in a number of ways, with ticks, scripts and types. The first of these (Figure 2.7) shows how a variable can be decorated with ticks, conforming to LaPlace notation. See §4.3 to understand why this is important and how it can be manipulated. A single tick introduces a sequence of ticks, a number (possibly negative) representing the number of ticks, or an arbitrary expression, as in f'{n-1}.

Figure 2.7 Tick decoration -- LaPlace notation

Mathematicians often use the second kind of decoration, subscripts and superscripts (collectively: scripts) to distinguish single-letter variables. Script notation is shown in Figure 2.8. A variable can be decorated with a subscript like X_i (entered as X_i) or decorated with a superscript like P__s (entered as P__s) or even decorated with both: Q_i_s (entered as Q_i_s).

Figure 2.8 Subscript and superscript notation

An underscore following an identifier acts like a binary operator, joining a variable with its subscript. Underscore can be used twice on a variable. The right operand of the second underscore is used as the superscript, as you can see from the examples above. If two underscores are used in a row, the subscript is taken to be empty and just a superscript is used. The keyboard symbol for subscript is A_i . When touched, the key supplies an underscore in the input area.

It is important not to confuse a subscripted variable with a function reference or an index. a_i, a(i) and a[i] are all displayed the same way; the first is a subscript (a_i), the second is a function reference with one parameter (a(i)) and the third is an index (a[i]).

It is also important not to confuse a superscripted variable with exponentiation. The keyboard symbol for exponentiation is X^y . When touched, the key supplies an exponentiation operator in the input area. Although the display forms are similar, A__x ( A__x) is not the same as A^x ( A^x). And while on this topic, it is also important not to confuse the exponentiation operator ^ with the Boolean and operator ∧. That is, A^x (A^x) is not the same as A∧x (A∧x).

Figure 2.9 Subscript and superscript decoration

A script decoration can be a simple symbol, like another identifier or an operator. It can also be an arbitrary expression, as shown in Figure 2.9. This allows variables like f__+ (f__+) and Q_(i-1) (Q_(i-1)).

The third kind of variable decoration specifies the type of a variable. The type decoration uses a single-letter suffix to distinguish composite and collection variables from numeric variables (Figure 2.10). This decoration can be a regular character easily entered from the regular keyboard or a special symbol found on a popup keyboard. If a regular character is used, there must be a space between the variable name and the suffix. Without a space, the suffix is taken to be part of the variable name. The parser replaces type suffixes with formal letter-like symbols that have a similar appearance: ⅈ, ɽ, ʋ, ƈ, ʈ, ʂ, ɱ and ɗ[1]. Being non-letters, these symbols need not be preceded by a space. The formal symbols are visible in the string form of expressions, such as that seen in the output area. The formal symbols are equivalent to their letter-based counterparts and the notations can be mixed.

(a) Keyboard (b) Formal
Figure 2.10 Type decoration

The display form of type-decorated variables does not necessarily show the type suffix. Rather, the typeset notation found in many mathematics textbooks is used; collection and composite variables are displayed in bold-face sans-serif font. The exceptions are complex variables, which are displayed using the suffix ⅈ, radial variables, which are displayed with an arrow above the variable name and string variables, which are displayed with an underscore.

For symmetry, and in some cases a requirement, the numeric nature of a variable may be enforced using a . suffix; but note a and a. are the same variable. One such situation arises in definitions (see §2.5) to disable parameter inference by providing an explicit type suffix.

The names of builtin functions cannot be used as variables. These are the trigonometric functions: sin, cos, tan, cot, sec, csc; their inverses: arcsin, arccos, arctan, arccot, arcsec, arccsc; and a handful of others: log, ln, root, det and if. Other names that look like variables but have special meanings are described in §2.10.1.